// 加载插件列表
async function loadPlugins() {
    try {
        const response = await fetch('/api/plugins');
        const result = await response.json();
        if (result.status === 'success') {
            const plugins = result.data;
            const container = document.getElementById('pluginContainer');
            if (!container) return;

            container.innerHTML = plugins.map(plugin => createPluginCard(plugin)).join('');
        }
    } catch (error) {
        console.error('Error loading plugins:', error);
        showToast('加载插件列表失败', 'error');
    }
}

function createPluginCard(plugin) {
    return `
        <div class="col-6 col-sm-4 col-md-3 col-lg-2">
            <div class="plugin-card" data-plugin-id="${plugin.id}" onclick="openPlugin('${plugin.id}')">
                <div class="plugin-icon">
                    <img src="/plugins/${plugin.id}/assets/icon.png" alt="${plugin.name}" onerror="this.src='/static/img/default-plugin-icon.png'">
                </div>
                <h6 class="plugin-name">${plugin.manifest.name}</h6>
            </div>
        </div>
    `;
}

function openPlugin(pluginId) {
    window.location.href = `/plugins/${pluginId}`;
}

// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
    // 加载插件列表
    loadPlugins();
}); 